/***************** MAPPINGS FOR GPIO ONLY ******************
*
* DIO1 Pin set and Data Direction mapping
*
* Port B layout is pins 0 to 7 (bit respective)
* Port C layout is pin 4 is bit 0
* Port F layout is pin 8 is bit 1
*
* Port B Data Direction is pins 0 to 7 (bit respective)
* Port C Data Direction is pin 7, bit 7
* Port F Data Direction is pin 8, bit 1
*
*
* DIO2 Pin set and Data Direction mapping
*
* LCD Pin set and Data Direction mapping
*
********************************************************/

//digital i/o registers
#define LCD_PORT_A 0x80840000
#define DIO1_PORT_B 0x80840004
#define DIO1_PORT_C 0x80840008
#define DIO1_PORT_F 0x80840030

//data direction registers
#define LCD_PORT_A_DR 0x80840010
#define DIO1_PORT_B_DR 0x80840014
#define DIO1_PORT_C_DR 0x80840018
#define DIO1_PORT_F_DR 0x80840034

//on-board leds (use bits 0 and 1)
#define ONBOARD_LEDS 0x80840020 

//xdio uses a different address base than the rest
#define XDIO_BASE 0x12c00000

//Offsets to help when using GPIO_BASE
#define GPIO_BASE 0x80840000
#define PORT_A_OFFSET 0x00
#define PORT_B_OFFSET 0x04
#define PORT_C_OFFSET 0x08
#define PORT_F_OffSET 0x30
#define PORT_A_DR_OFFSET 0x04
#define PORT_B_DR_OFFSET 0x14
#define PORT_C_DR_OFFSET 0x18
#define PORT_F_DR_OFFSET 0x34
#define ONBOARD_LEDS_OFFSET 0x20

//debounce registers. Besides port b, I am guessing at addresses
#define PORT_A_DEBOUNCE 0xFFFFFFFF //find out
#define PORT_B_DEBOUNCE 0x808400C4
#define PORT_C_DEBOUNCE 0xFFFFFFFF //find out
#define PORT_F_DEBOUNCE 0xFFFFFFFF //find out

//some misc helper defines
#define READ 0
#define WRITE 1
#define MMAP_TABLE_SIZE 4
#define FD_TABLE_SIZE 2
#define PAGE_START 0
/************ BIT FIELD STRUCT ***********************************
*
* header_mapping can be used on DIO1 and LCD where pins 
* are respective to bits
*
* onboard_led_mapping should be obvious
*
*****************************************************************/

struct header_mapping{

	//simple enough
	unsigned int pin_0: 1;
	unsigned int pin_1: 1;
	unsigned int pin_2: 1;
	unsigned int pin_3: 1;
	unsigned int pin_4: 1;
	unsigned int pin_5: 1;
	unsigned int pin_6: 1;
	unsigned int pin_7: 1;
	
}


struct onboard_led_mapping{

	//as easy
	unsigned int led_0: 1;
	unsigned int led_1: 1;
}


//meant to be called via other functions, but available for you if needed
void* popen(char* header, char port);

//type safe read
unsigned int pread(struct *header_mapping, int bit_start, int bit_end);

//type safe write
unsigned int pwrite(unsigned char hex_data, struct *header_mapping, int bit_start, int size);

//for creating reference copies
int retain(struct *header_mapping);

//for releasing reference copies
int release(struct *header_mapping);

//clear the register
void clear(struct *header_mapping);


/************** OTHER STUFF NEEDED **********************
*
*
*********************************************************/

//not using????
volatile unsigned int *PADR, *PADDR, *PBDR, *PBDDR, *PCDR, *PCDDR, *PFDR, *PFDDR;

//because of two addressing schemes, 0 will be GPIO_BASE and 1 will be XDIO_BASE
static int fd[] = NULL;

//jic there are more than one map
static char *maps = NULL;


/************* SOME OTHER FUNCTIONS **********************
*
*
**********************************************************/

//private scope??? Bypasses the validator of init
struct* init_gpio(char *address, int DIRECTION);

